<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveRecord::Locking::Optimistic::ClassMethods</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveRecord::Locking::Optimistic::ClassMethods</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/rails/activerecord/lib/active_record/locking/optimistic_rb.html">
                vendor/rails/activerecord/lib/active_record/locking/optimistic.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001108">extended</a>&nbsp;&nbsp;
      <a href="#M001111">locking_column</a>&nbsp;&nbsp;
      <a href="#M001109">locking_enabled?</a>&nbsp;&nbsp;
      <a href="#M001112">quoted_locking_column</a>&nbsp;&nbsp;
      <a href="#M001113">reset_locking_column</a>&nbsp;&nbsp;
      <a href="#M001110">set_locking_column</a>&nbsp;&nbsp;
      <a href="#M001114">update_counters_with_lock</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEFAULT_LOCKING_COLUMN</td>
          <td>=</td>
          <td class="context-item-value">'lock_version'</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M001108" class="method-detail">
        <a name="M001108"></a>

        <div class="method-heading">
          <a href="#M001108" class="method-signature">
          <span class="method-name">extended</span><span class="method-args">(base)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001108-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001108-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 101</span>
101:         <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">extended</span>(<span class="ruby-identifier">base</span>)
102:           <span class="ruby-keyword kw">class</span> <span class="ruby-operator">&lt;&lt;</span><span class="ruby-identifier">base</span>
103:             <span class="ruby-identifier">alias_method_chain</span> <span class="ruby-identifier">:update_counters</span>, <span class="ruby-identifier">:lock</span>
104:           <span class="ruby-keyword kw">end</span>
105:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001111" class="method-detail">
        <a name="M001111"></a>

        <div class="method-heading">
          <a href="#M001111" class="method-signature">
          <span class="method-name">locking_column</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The version column used for optimistic locking. Defaults to lock_version.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001111-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001111-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 122</span>
122:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">locking_column</span>
123:           <span class="ruby-identifier">reset_locking_column</span>
124:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001109" class="method-detail">
        <a name="M001109"></a>

        <div class="method-heading">
          <a href="#M001109" class="method-signature">
          <span class="method-name">locking_enabled?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Is optimistic locking enabled for this table? Returns true if the
lock_optimistically flag is set to true (which it is, by default) and the
table includes the <a href="ClassMethods.html#M001111">locking_column</a>
column (defaults to lock_version).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001109-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001109-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 111</span>
111:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">locking_enabled?</span>
112:           <span class="ruby-identifier">lock_optimistically</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">columns_hash</span>[<span class="ruby-identifier">locking_column</span>]
113:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001112" class="method-detail">
        <a name="M001112"></a>

        <div class="method-heading">
          <a href="#M001112" class="method-signature">
          <span class="method-name">quoted_locking_column</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Quote the column name used for optimistic locking.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001112-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001112-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 127</span>
127:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">quoted_locking_column</span>
128:           <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">quote_column_name</span>(<span class="ruby-identifier">locking_column</span>)
129:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001113" class="method-detail">
        <a name="M001113"></a>

        <div class="method-heading">
          <a href="#M001113" class="method-signature">
          <span class="method-name">reset_locking_column</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Reset the column used for optimistic locking back to the lock_version
default.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001113-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001113-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 132</span>
132:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset_locking_column</span>
133:           <span class="ruby-identifier">set_locking_column</span> <span class="ruby-constant">DEFAULT_LOCKING_COLUMN</span>
134:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001110" class="method-detail">
        <a name="M001110"></a>

        <div class="method-heading">
          <a href="#M001110" class="method-signature">
          <span class="method-name">set_locking_column</span><span class="method-args">(value = nil, &amp;block)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Set the column to use for optimistic locking. Defaults to lock_version.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001110-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001110-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 116</span>
116:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_locking_column</span>(<span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
117:           <span class="ruby-identifier">define_attr_method</span> <span class="ruby-identifier">:locking_column</span>, <span class="ruby-identifier">value</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
118:           <span class="ruby-identifier">value</span>
119:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001114" class="method-detail">
        <a name="M001114"></a>

        <div class="method-heading">
          <a href="#M001114" class="method-signature">
          <span class="method-name">update_counters_with_lock</span><span class="method-args">(id, counters)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
make sure the lock version column gets updated when counters are updated.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001114-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001114-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/locking/optimistic.rb, line 138</span>
138:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_counters_with_lock</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">counters</span>)
139:           <span class="ruby-identifier">counters</span> = <span class="ruby-identifier">counters</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">locking_column</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">locking_enabled?</span>
140:           <span class="ruby-identifier">update_counters_without_lock</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">counters</span>)
141:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>